﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace syc.Fc
{
    public partial class 保护器入库单 : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            int id = 0;

            if (!this.IsPostBack)
            {
                if (Request.QueryString["ID"] != null)
                {
                    int.TryParse(Request.QueryString["ID"], out id);
                }

                if (id > 0)
                {
                    this.SqlDataSource1.SelectParameters["ID"].DefaultValue = id.ToString();
                    this.SqlDataSource1.Select(DataSourceSelectArguments.Empty);
                }
            }
        }


        protected void SqlDataSource1_Selected(object sender, SqlDataSourceStatusEventArgs e)
        {
            if (!Convert.IsDBNull(e.Command.Parameters[1].Value))
            {
                this.BillID.Text = ((int)e.Command.Parameters[0].Value).ToString();
                this.Date1.Text = ((DateTime)e.Command.Parameters[1].Value).ToLongDateString();

                if (!Convert.IsDBNull(e.Command.Parameters[2].Value))
                {
                    this.TieZhi.Text = (String)e.Command.Parameters[2].Value;
                }
                if (!Convert.IsDBNull(e.Command.Parameters[3].Value))
                {
                    this.SuZhi.Text = (String)e.Command.Parameters[3].Value;
                }
                this.TaoShu.Text = ((int)e.Command.Parameters[4].Value).ToString();
                this.JianShu.Text = ((int)e.Command.Parameters[5].Value).ToString();
                if (!Convert.IsDBNull(e.Command.Parameters[6].Value))
                {
                    this.ZhiJianYuan.Text = (String)e.Command.Parameters[6].Value;
                }
                if (!Convert.IsDBNull(e.Command.Parameters[7].Value))
                {
                    this.BeiZhu.Text = (String)e.Command.Parameters[7].Value;
                }
                if (!Convert.IsDBNull(e.Command.Parameters[8].Value))
                {
                    this.JieLun.Text = (String)e.Command.Parameters[8].Value;
                }
                if (!Convert.IsDBNull(e.Command.Parameters[9].Value))
                {
                    this.PanDing.Text = (String)e.Command.Parameters[9].Value;
                }
                if (!Convert.IsDBNull(e.Command.Parameters[10].Value))
                {
                    this.ZhiPiao.Text = (String)e.Command.Parameters[10].Value;
                }
                this.PDZ.Visible = (bool)e.Command.Parameters[11].Value;
                if (this.PDZ.Visible)
                {
                    this.Button_Check.Text = "取消盖章";
                }
                else
                {
                    this.Button_Check.Text = "盖 章";
                }
            }
        }

        protected void Button_Check_Click(object sender, EventArgs e)
        {
            string op = (string)this.Session["OperatorName"];
            if (op == null)
            {
                op = "";
            }
            if (this.PDZ.Visible)
            {
                this.SqlDataSource1.UpdateParameters["ID"].DefaultValue = this.BillID.Text;
                this.SqlDataSource1.UpdateParameters["判定员"].DefaultValue = op;
                this.SqlDataSource1.UpdateParameters["合格"].DefaultValue = "false";
                if (this.SqlDataSource1.Update() > 0)
                {
                    this.PDZ.Visible = false;
                    this.Button_Check.Text = "盖 章";
                    this.JieLun.Text = "";
                }
                
            }
            else
            {
                this.SqlDataSource1.UpdateParameters["ID"].DefaultValue = this.BillID.Text;
                this.SqlDataSource1.UpdateParameters["判定员"].DefaultValue = op;
                this.SqlDataSource1.UpdateParameters["合格"].DefaultValue = "true";
                if (this.SqlDataSource1.Update() > 0)
                {
                    this.PDZ.Visible = true;
                    this.Button_Check.Text = "取消盖章";
                    this.JieLun.Text = "合格入库";
                }
                
            }
        }

    }
}
